package com.onlinevideo.service.impl;


import com.onlinevideo.dao.RoleAuthorityDao;
import com.onlinevideo.dao.impl.RoleAuthorityDaoImpl;
import com.onlinevideo.entity.PageBean;
import com.onlinevideo.entity.RoleAuthority;
import com.onlinevideo.entity.RoleAuthorityDTO;
import com.onlinevideo.service.RoleAuthorityService;


import java.util.List;

public class RoleAuthorityServiceImpl implements RoleAuthorityService {

    private RoleAuthorityDao roleAuthorityDao = new RoleAuthorityDaoImpl();


    @Override
    public int insert(RoleAuthority roleAuthority) {
        return roleAuthorityDao.insert(roleAuthority);
    }

    @Override
    public int delete(Long id) {
        return roleAuthorityDao.delete(id);
    }

    @Override
    public  List<RoleAuthorityDTO> queryByRoleId(Long roleId) {
        return roleAuthorityDao.queryByRoleId(roleId);
    }

    @Override
    public List<RoleAuthority> queryAll() {
        return roleAuthorityDao.queryAll();
    }

    @Override
    public PageBean<RoleAuthority> findAllRoleAuthorityWithPage(Integer pageNo, Integer pageSize) {

        List<RoleAuthority> roleAuthorities = roleAuthorityDao.queryAll();

        Integer totalCount = roleAuthorities.size();

        PageBean<RoleAuthority> page = new PageBean<RoleAuthority>(pageNo,pageSize,totalCount);

        Integer startIndex = page.getStartIndex();

        page.setData(roleAuthorityDao.queryAllByStartIndexAndPageSize(startIndex,pageSize));

        return page;
    }
}
